import axios from 'axios';

// 字典全查询接口，使用 GET 请求
export const getAllSysDict = (pageNum, pageSize) => {
    return axios.get('http://localhost:8080/SysDict/getPageList', {
        params: {
            pageNum,
            pageSize
        }
    });
};

// 按照字典名称模糊查询接口，使用 POST 请求，参数类型为 application/x-www-form-urlencoded
export const searchSysDictByName = (pageNum, pageSize, dictName) => {
    const params = new URLSearchParams();
    params.append('pageNum', pageNum);
    params.append('pageSize', pageSize);
    params.append('dictName', dictName);

    return axios.post('http://localhost:8080/SysDict/getByName', params, {
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        }
    });
};

// 字典添加接口
export const addSysDict = (data) => {
    return axios.post('http://localhost:8080/SysDict/add', data, {
        headers: {
            'Content-Type': 'application/json'
        }
    });
};
// 登录
export const login = (name , password) => {

    const params = new URLSearchParams();
    params.append('accountName', name);
    params.append('password', password);

    return axios.post('http://localhost:8080/login', params, {
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        }
    });
};

// 修改 register 函数
export const register = (data) => {
    return axios.post('http://localhost:8080/auth/register', data, {
        headers: {
            'Content-Type': 'application/json'
        }
    });
};

// src/api/sysDict.js
export const check = (data) => {
    return axios.post('http://localhost:8080/auth/checkName', data, {
        headers: {
            'Content-Type': 'application/json'
        }
    });
};

export const updateSysDict = (data) => {
    return axios.post('http://localhost:8080/SysDict/update', data, {
        headers: {
            'Content-Type': 'application/json'
        }
    });
};

// 字典删除接口
export const deleteSysDict = (id) => {
    return axios.delete(`http://localhost:8080/SysDict/delete/${id}`);
};


// 新 API：根据字典编码获取字典项分页列表
export const getDictItemPageListByDictCode = (pageNum, pageSize, dictCode) => {
    return axios({
        url: 'http://localhost:8080/SysDictItem/dictConfig/getPageList',
        method: 'post',
        params: {
            pageNum,
            pageSize,
            dictCode
        }
    });
};

// 新 API：删除字典项
export const deleteDictItemById = (id) => {
  return axios.delete(`http://localhost:8080/SysDictItem/dictConfig/delete/${id}`);
};

// 新 API：添加字典项
export const addDictItem = (sysDictItemVO) => {
  return axios.post('http://localhost:8080/SysDictItem/dictConfig/add', sysDictItemVO, {
    headers: {
      'Content-Type': 'application/json'
    }
  });
};




